import { defineStore } from 'pinia';
import { AES, enc} from 'crypto-js';


export const useCommonStore = defineStore(
    'useCommonStore',
    {
        state(){
            return{
                userInfo: {},
                token: '',
                num:''
            }
        },
        getters:{
            tokenVal(){
               return AES.decrypt(this.token,'asfssdajeubvdhauk23jaksn').toString(enc.Utf8)
            },
            userInfoVal(){
                return this.userInfo
            }
        },
        actions:{
            setUserInfo(userInfo_){
                this.userInfo = userInfo_
            },
            setToken(token_){
                let __newToken = AES.encrypt(token_,'asfssdajeubvdhauk23jaksn').toString()
                sessionStorage.setItem('common-store-token', __newToken)
                this.token = token_ ? __newToken : token_
            },
            setNum(num_){
                this.num = num_
            }        
        }

    }
)